//package com.dc.dbus.netty.exception;
//
//import java.io.IOException;
//import java.util.Arrays;
//import java.util.List;
//import java.util.concurrent.Executors;
//import java.util.concurrent.TimeUnit;
//
//import com.dc.dbus.netty.ITestService;
//import com.dc.dbus.session.client.Client;
//import com.dc.dbus.session.listener.ClientSideEventListener;
//import com.dc.dbus.session.listener.ServerSideEventListener;
//import com.dc.dbus.session.server.Server;
//import com.dc.dbus.transport.commons.ClientSideTransport;
//import com.dc.dbus.transport.commons.ServerSideTransport;
//import com.dc.dbus.transport.netty.client.NettyClientSideTransport;
//import com.dc.dbus.transport.netty.register.ServiceRegister;
//import com.dc.dbus.transport.netty.register.ZookeeperServiceRegister;
//import com.dc.dbus.transport.netty.server.NettyServerSideTransport;
//
//public class ServiceDisconnectTest_Server {
//
//	protected final static ClientSideEventListener clientSideEventListener = new ClientSideEventListener() {
//		@Override
//		public void exception(String message, Exception e) {
//			System.err.println(message);
//			e.printStackTrace(System.err);
//		}
//	};
//	
//	protected final static ServerSideEventListener serverSideEventListener = new ServerSideEventListener() {
//		@Override
//		public void queueFull(String message, Exception e) {
//			System.err.println(message);
//			e.printStackTrace(System.err);
//		}
//
//		@Override
//		public void methodExcuteException(String message, Throwable t) {
//			System.err.println(message);
//			t.printStackTrace(System.err);
//		}
//
//		@Override
//		public void dbusException(String message, Exception e) {
//			System.err.println(message);
//			e.printStackTrace(System.err);
//		}
//	};
//	
//	public static Client getClient(String serviceName) throws IOException {
//		
//		List<String> serviceNames = Arrays.asList(new String[] {serviceName});
//		ServiceRegister serviceRegister = new ZookeeperServiceRegister("127.0.0.1:2181");
//		ClientSideTransport clientSideTansport = new NettyClientSideTransport(serviceNames, serviceRegister, 4);
//		Client client = new Client(serviceName, clientSideTansport, clientSideEventListener);
//		
//		return client;
//	}
//	
//	public static Server initServer(String serviceName, String[] serviceRegion, int servicePort, int sessionTimeout) throws IOException {
//		
//		ServiceRegister serviceRegister = new ZookeeperServiceRegister("127.0.0.1:2181", sessionTimeout);
//		
//		ServerSideTransport serverSideTansport = new NettyServerSideTransport(serviceName, serviceRegion, 
//				servicePort, serviceRegister);
//		
//		Server server = new Server(serverSideTansport, null, serverSideEventListener);
//		
//		return server;
//	}
//	
//	public static void main(String[] args) throws Exception {
//		
//		System.out.println("启动服务端");
//		
//		ITestService testService = new ITestService() {
//			@Override
//			public int test3(String router, String p1) {
//				System.out.println("get req: test3:" + p1);
//				return 666;
//			}
//			
//			@Override
//			public Integer test2(String router, String p1) {
//				System.out.println("get req: test2:" + p1);
//				return 666666;
//			}
//			
//			@Override
//			public String test1(String router, String p1) {
//				System.out.println("get req: test1:" + p1);
//				
//				try {
//					TimeUnit.MILLISECONDS.sleep(10000);
//				} catch (InterruptedException e) {
//					e.printStackTrace();
//				}
//				
//				System.out.println("get req: test1:" + p1 + " and return");
//				
//				return "6";
//			}
//		};
//		
//		ServiceRegister serviceRegister = new ZookeeperServiceRegister("127.0.0.1:2181", 500);
//		ServerSideTransport serverSideTansport = new NettyServerSideTransport("ServerName-Demo", new String[]{"ts0", "ts1"}, 
//				9001, serviceRegister);
//		// TODO 必须指定为Executor才能出现channel被关闭的情况（否则是先处理完调用，再处理channel关闭事件）
//		Server server = new Server(serverSideTansport, Executors.newCachedThreadPool(), serverSideEventListener);
//		
//		server.registerProducter(ITestService.class, testService);
//		
//		// TODO 调用过程为10秒，中途需手动断开服务端或客户端
//	}
//}
